import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

public class ThreadDemo {
    static class MyThread extends Thread{
        private BlockingQueue<Runnable> queue = null;

        public MyThread(BlockingQueue<Runnable> queue) {
            this.queue = queue;
        }

        @Override
        public void run() {
            while (true) {
                try {
                    queue.take().run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    static class ThreadPool {
        private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();

        private List<Thread> list = new ArrayList<>();

/*        public void submit(Runnable command) throws InterruptedException {
            if(list.size() < 10) {
                Thread t1 = new MyThread(queue);
                t1.start();
                list.add(t1);
            }
            queue.put(command);
        }*/
    }
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable  = new Runnable() {
            @Override
            public void run() {
                System.out.println("1");
            }
        };
        ThreadPool pool = new ThreadPool();
        Thread t1 = new MyThread(pool.queue);
        t1.start();

        Thread.sleep(3000);
        pool.queue.put(runnable);
    }
}
